package edu.hunau.cxb18.spring.annotation.service.impl;

import edu.hunau.cxb18.spring.annotation.dao.UserDao;
import edu.hunau.cxb18.spring.annotation.pojo.User;
import edu.hunau.cxb18.spring.annotation.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * @author hb
 * @create 2020-03-11 10:48
 */
@Service
public class UserServiceImpl implements UserService {
    //为属性提供getter和setter方法
    /*@Autowired
    @Qualifier("userDaoMybatisImpl")*/

    /*@Inject
    @Named("userDaoImpl")*/
    private UserDao userDao;

    @Override
    public void regist(User user) {
        userDao.insertUser(user);
        System.out.println("UserServiceImpl#注册用户。。。");
    }

    @Override
    public User addUser(User user) {
        if (2>1) {
            throw new RuntimeException("自定义的一个异常。。");
        }
        return user;
    }

    public UserDao getUserDao() {
        return userDao;
    }

    @Autowired(required = false)
    public void setUserDao(@Qualifier("userDaoMybatisImpl") UserDao userDao) {
        this.userDao = userDao;
    }
}
